﻿Imports System.Windows.Input
Imports System.Collections.ObjectModel
Imports PTIC_Util

''' <summary>
''' 
''' </summary>
''' <remarks></remarks>
Public Class ViewModelMainMenuItem
    Inherits ViewModelBase

    'icone, command, titre, separator?
    'si can execute es a false il devient grisé si il et une terminaisn

    ''' <summary>
    ''' 
    ''' </summary>
    ''' <remarks></remarks>


    Private _Title As String
    Public Property Title As String
        Get
            Return _Title
        End Get
        Set(ByVal value As String)
            OnPropertyChanging("Title")
            Dim args As New PropertyChangeEventArgs(Of String)(_Title, value)
            OnTitleChange(args)
            _Title = args.NewValue
            OnPropertyChanged("Title")
        End Set
    End Property
    Protected Overridable Sub OnTitleChange(ByVal args As PropertyChangeEventArgs(Of String))
        RaiseEvent TitleChange(Me, args)
    End Sub
    Public Event TitleChange As PropertyChangeEventHandler(Of String)

    Private _Icone As String
    Public Property Icone As String
        Get
            Return _Icone
        End Get
        Set(ByVal value As String)
            OnPropertyChanging("Icone")
            Dim args As New PropertyChangeEventArgs(Of String)(_Icone, value)
            OnIconeChange(args)
            _Icone = args.NewValue
            OnPropertyChanged("Icone")
        End Set
    End Property
    Protected Overridable Sub OnIconeChange(ByVal args As PropertyChangeEventArgs(Of String))
        RaiseEvent IconeChange(Me, args)
    End Sub
    Public Event IconeChange As PropertyChangeEventHandler(Of String)

    Private _Shortcut As String
    Public Property Shortcut As String
        Get
            Return _Shortcut
        End Get
        Set(ByVal value As String)
            OnPropertyChanging("Shortcut")
            Dim args As New PropertyChangeEventArgs(Of String)(_Shortcut, value)
            OnShortcutChange(args)
            _Shortcut = args.NewValue
            OnPropertyChanged("Shortcut")
        End Set
    End Property
    Protected Overridable Sub OnShortcutChange(ByVal args As PropertyChangeEventArgs(Of String))
        RaiseEvent ShortcutChange(Me, args)
    End Sub
    Public Event ShortcutChange As PropertyChangeEventHandler(Of String)


    Private _Command As ICommand
    Public Property Command As Object
        Get
            Return _Command
        End Get
        Set(ByVal value As Object)
            Dim newvalue = value
            Dim meth = TryCast(value, System.Delegate)
            If meth IsNot Nothing Then
                newvalue = New SimpleCommand() With {.Method = meth}
            End If
            OnPropertyChanging("Command")
            Dim args As New PropertyChangeEventArgs(Of Object)(_Command, newvalue)
            OnCommandChange(args)
            _Command = args.NewValue
            OnPropertyChanged("Command")
        End Set
    End Property
    Protected Overridable Sub OnCommandChange(ByVal args As PropertyChangeEventArgs(Of Object))
        RaiseEvent COmmandChange(Me, args)
    End Sub
    Public Event CommandChange As PropertyChangeEventHandler(Of Object)

    Private _children As New ObservableCollection(Of ViewModelMainMenuItem)
    ''' <summary>
    ''' 
    ''' </summary>
    ''' <remarks></remarks>
    Public ReadOnly Property Children As ObservableCollection(Of ViewModelMainMenuItem)
        Get
            Return _children
        End Get
    End Property

    
End Class

Friend Class SimpleCommand
    Implements ICommand

    Private Function CanExecute(ByVal parameter As Object) As Boolean Implements System.Windows.Input.ICommand.CanExecute
        Return True
    End Function

    Friend Method As System.Delegate

    Private Event CanExecuteChanged(ByVal sender As Object, ByVal e As System.EventArgs) Implements System.Windows.Input.ICommand.CanExecuteChanged

    Private Sub Execute(ByVal parameter As Object) Implements System.Windows.Input.ICommand.Execute
        Method.DynamicInvoke(parameter)
    End Sub
End Class